<?php
class commentsControl extends Control{
    function comments(){
        $_POST['wid']=$_POST['wid'];
        if(empty($_SESSION['uid']) || !isset($_SESSION['uid']) || empty($_COOKIE['uid'])){
            echo 'login';
            exit;
        }else{
        $_POST['uid']=isset($_SESSION['uid']) || isset($_COOKIE['uid'])?$_COOKIE['uid']:$_SESSION['uid'];
        
        $content=$_POST['content'];
        $pattern='/\/\#([\w]+)@/i';
        $replacement="<img src='/images/exp/\\1.gif'/>";
        $content=preg_replace($pattern, $replacement, $content);
        $_POST['comment']=$content;
        $_POST['time']=time();


       
        $db=M('work_comments');
        if($db->add()){
            $udb=M('user');//返回用户信息
            $uid=$_POST['uid'];
            $ures=$udb->where("uid={$uid}")->all();
            $userArr=array(
                'username'=>$ures[0]['username'],
                'uid'=>$ures[0]['uid'],
                'city'=>$ures[0]['city'],
                'profession'=>$ures[0]['profession'],
                'img'=>$ures[0]['image'],
                'comment'=>$_POST['comment']
            );
            $userArr=json_encode($userArr);
            echo $userArr;
        }else{
            echo 0;
        }
        
        
        
        }
    }
    
}
